﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract Razdoblje typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class RazdobljeDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<RazdobljeDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.Razdoblje _currentRazdoblje = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxRazdobljeDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxRazdobljeErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxRazdobljeBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DatumOd property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDatumOdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DatumDo property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDatumDoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DateCreated property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDateCreatedDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DateModified property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDateModifiedDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IDUserCreated property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDUserCreatedDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IDUserModified property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDUserModifiedDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Koristiti property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxKoristitiDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.Razdoblje> _RazdobljeList;
				
		/// <summary> 
		/// The list of Razdoblje to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.Razdoblje> RazdobljeList
		{
			get {return this._RazdobljeList;}
			set
			{
				this._RazdobljeList = value;
				this.uxRazdobljeBindingSource.DataSource = null;
				this.uxRazdobljeBindingSource.DataSource = value;
				this.uxRazdobljeDataGridView.DataSource = null;
				this.uxRazdobljeDataGridView.DataSource = this.uxRazdobljeBindingSource;				
				//this.uxRazdobljeBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxRazdobljeBindingSource_ListChanged);
				this.uxRazdobljeBindingSource.CurrentItemChanged += new System.EventHandler(OnRazdobljeBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnRazdobljeBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentRazdoblje = uxRazdobljeBindingSource.Current as Entities.Razdoblje;
			
			if (_currentRazdoblje != null)
			{
				_currentRazdoblje.Validate();
			}
			//_Razdoblje.Validate();
			OnCurrentEntityChanged();
		}

		//void uxRazdobljeBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.Razdoblje"/> instance.
		/// </summary>
		public Entities.Razdoblje SelectedRazdoblje
		{
			get {return this._currentRazdoblje;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxRazdobljeDataGridView.VirtualMode;}
			set
			{
				this.uxRazdobljeDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxRazdobljeDataGridView.AllowUserToAddRows;}
			set {this.uxRazdobljeDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxRazdobljeDataGridView.AllowUserToDeleteRows;}
			set {this.uxRazdobljeDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxRazdobljeDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxRazdobljeDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="RazdobljeDataGridViewBase"/> class.
		/// </summary>
		public RazdobljeDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxRazdobljeDataGridView = new System.Windows.Forms.DataGridView();
			this.uxRazdobljeBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxRazdobljeErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDatumOdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDatumDoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDateCreatedDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDateModifiedDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDUserCreatedDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDUserModifiedDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxKoristitiDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxRazdobljeErrorProvider
			// 
			this.uxRazdobljeErrorProvider.ContainerControl = this;
			this.uxRazdobljeErrorProvider.DataSource = this.uxRazdobljeBindingSource;						
			// 
			// uxRazdobljeDataGridView
			// 
			this.uxRazdobljeDataGridView.AutoGenerateColumns = false;
			this.uxRazdobljeDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxRazdobljeDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxDatumOdDataGridViewColumn,
		this.uxDatumDoDataGridViewColumn,
		this.uxDateCreatedDataGridViewColumn,
		this.uxDateModifiedDataGridViewColumn,
		this.uxIDUserCreatedDataGridViewColumn,
		this.uxIDUserModifiedDataGridViewColumn,
		this.uxKoristitiDataGridViewColumn			});
			this.uxRazdobljeDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxRazdobljeDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxRazdobljeDataGridView.Name = "uxRazdobljeDataGridView";
			this.uxRazdobljeDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxRazdobljeDataGridView.TabIndex = 0;	
			this.uxRazdobljeDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxRazdobljeDataGridView.EnableHeadersVisualStyles = false;
			this.uxRazdobljeDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnRazdobljeDataGridViewDataError);
			this.uxRazdobljeDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnRazdobljeDataGridViewCellValueNeeded);
			this.uxRazdobljeDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnRazdobljeDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxDatumOdDataGridViewColumn
			//
			this.uxDatumOdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDatumOdDataGridViewColumn.DataPropertyName = "DatumOd";
			this.uxDatumOdDataGridViewColumn.HeaderText = "DatumOd";
			this.uxDatumOdDataGridViewColumn.Name = "uxDatumOdDataGridViewColumn";
			this.uxDatumOdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDatumOdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDatumOdDataGridViewColumn.ReadOnly = false;		
			//
			// uxDatumDoDataGridViewColumn
			//
			this.uxDatumDoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDatumDoDataGridViewColumn.DataPropertyName = "DatumDo";
			this.uxDatumDoDataGridViewColumn.HeaderText = "DatumDo";
			this.uxDatumDoDataGridViewColumn.Name = "uxDatumDoDataGridViewColumn";
			this.uxDatumDoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDatumDoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDatumDoDataGridViewColumn.ReadOnly = false;		
			//
			// uxDateCreatedDataGridViewColumn
			//
			this.uxDateCreatedDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDateCreatedDataGridViewColumn.DataPropertyName = "DateCreated";
			this.uxDateCreatedDataGridViewColumn.HeaderText = "DateCreated";
			this.uxDateCreatedDataGridViewColumn.Name = "uxDateCreatedDataGridViewColumn";
			this.uxDateCreatedDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDateCreatedDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDateCreatedDataGridViewColumn.ReadOnly = false;		
			//
			// uxDateModifiedDataGridViewColumn
			//
			this.uxDateModifiedDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDateModifiedDataGridViewColumn.DataPropertyName = "DateModified";
			this.uxDateModifiedDataGridViewColumn.HeaderText = "DateModified";
			this.uxDateModifiedDataGridViewColumn.Name = "uxDateModifiedDataGridViewColumn";
			this.uxDateModifiedDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDateModifiedDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDateModifiedDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDUserCreatedDataGridViewColumn
			//
			this.uxIDUserCreatedDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDUserCreatedDataGridViewColumn.DataPropertyName = "IDUserCreated";
			this.uxIDUserCreatedDataGridViewColumn.HeaderText = "IDUserCreated";
			this.uxIDUserCreatedDataGridViewColumn.Name = "uxIDUserCreatedDataGridViewColumn";
			this.uxIDUserCreatedDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDUserCreatedDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDUserCreatedDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDUserModifiedDataGridViewColumn
			//
			this.uxIDUserModifiedDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDUserModifiedDataGridViewColumn.DataPropertyName = "IDUserModified";
			this.uxIDUserModifiedDataGridViewColumn.HeaderText = "IDUserModified";
			this.uxIDUserModifiedDataGridViewColumn.Name = "uxIDUserModifiedDataGridViewColumn";
			this.uxIDUserModifiedDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDUserModifiedDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDUserModifiedDataGridViewColumn.ReadOnly = false;		
			//
			// uxKoristitiDataGridViewColumn
			//
			this.uxKoristitiDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxKoristitiDataGridViewColumn.DataPropertyName = "Koristiti";
			this.uxKoristitiDataGridViewColumn.HeaderText = "Koristiti";
			this.uxKoristitiDataGridViewColumn.Name = "uxKoristitiDataGridViewColumn";
			this.uxKoristitiDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxKoristitiDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxKoristitiDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxRazdobljeDataGridView);
			this.Name = "RazdobljeDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				RazdobljeDataGridViewEventArgs args = new RazdobljeDataGridViewEventArgs();
				args.Razdoblje = _currentRazdoblje;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class RazdobljeDataGridViewEventArgs : System.EventArgs
		{
			private Entities.Razdoblje	_Razdoblje;
	
			/// <summary>
			/// the  Entities.Razdoblje instance.
			/// </summary>
			public Entities.Razdoblje Razdoblje
			{
				get { return _Razdoblje; }
				set { _Razdoblje = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxRazdobljeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnRazdobljeDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxRazdobljeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnRazdobljeDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxRazdobljeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].ID;
						break;
					case "uxDatumOdDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].DatumOd;
						break;
					case "uxDatumDoDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].DatumDo;
						break;
					case "uxDateCreatedDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].DateCreated;
						break;
					case "uxDateModifiedDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].DateModified;
						break;
					case "uxIDUserCreatedDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].IDUserCreated;
						break;
					case "uxIDUserModifiedDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].IDUserModified;
						break;
					case "uxKoristitiDataGridViewColumn":
						e.Value = RazdobljeList[e.RowIndex].Koristiti;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxRazdobljeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnRazdobljeDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxRazdobljeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						RazdobljeList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxDatumOdDataGridViewColumn":
						RazdobljeList[e.RowIndex].DatumOd = (System.DateTime)e.Value;
						break;
					case "uxDatumDoDataGridViewColumn":
						RazdobljeList[e.RowIndex].DatumDo = (System.DateTime)e.Value;
						break;
					case "uxDateCreatedDataGridViewColumn":
						RazdobljeList[e.RowIndex].DateCreated = (System.DateTime)e.Value;
						break;
					case "uxDateModifiedDataGridViewColumn":
						RazdobljeList[e.RowIndex].DateModified = (System.DateTime)e.Value;
						break;
					case "uxIDUserCreatedDataGridViewColumn":
						RazdobljeList[e.RowIndex].IDUserCreated = (System.Int32)e.Value;
						break;
					case "uxIDUserModifiedDataGridViewColumn":
						RazdobljeList[e.RowIndex].IDUserModified = (System.Int32)e.Value;
						break;
					case "uxKoristitiDataGridViewColumn":
						RazdobljeList[e.RowIndex].Koristiti = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
